Using the Central Accordion Tab Component
Table of Contents
Determining When the User Selects a Tab
Now that you know how to add tabs to the component, the next step is to figure out how to determine when the user selects a tab, and which tab she selected.
In order to determine when the user selects a tab, you need to implement
a change handler function. This function is called whenever the selected
index of the component changes (in most cases this occurs when the
users selects a tab). You can specify a change handler for your component
using the setChangeHandler method.
The setChangeHandler method of the Accordion Tab component
takes the name of the function that is called when the selected index
of the component changes. It will be called in the same scope as the
component (that is the same timeline). If the function exists in a
different scope than the component, you can pass in a reference to
that scope as the second argument.
The following example demonstrates how to add a change handler to the addItem example from above.
function onActivate()
{
myTab.additem("Tab 1");
myTab.additem("Tab 2");
myTab.additem("Tab 3");
myTab.setChangeHandler("onTabChange");
}
function onTabChange()
{
var tabLabel = myTab.getSelectedItem().label;
trace("Tab Selected : " + tabLabel);
}
Central.initApplication(this, this);
First use the setChangeHandler component to specify that
the onTabChange function be called when the selected tab changes.
Then define the onTabChange function. All you do here
is get a reference to the currently selected tab (by calling getSelectedItem),
and trace out its label.
In order to test it, open the Central Debug Panel (Window > Other Panels > Central Debug Panel) and then publish the application into Central. Switch to Central, reload the test application and then select a tab. If you look at the debug panel, you should see the trace information for each tab selected.
You can now add code that changes the state of your application when a new tab is selected.